using System.Collections;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;

namespace ComponentSystem.Sample
{
    /// <summary>
    /// 测试实体CSharp
    /// </summary>
    public class TestEntityCSharp : MonoBehaviour
    {
        /// <summary>
        /// 测试实体CSharp添加组件
        /// </summary>
        [UnityTest]
        public IEnumerator TestEntity_CSharp_AddGetComponent()
        {
            var entity = new EntityCSharpDemo();
            entity.Initialization();
            Assert.IsNotNull(entity.GetComponent<ComponentDemo_1>());
            Assert.IsNotNull(entity.GetComponent<ComponentDemo_2>());
            yield return null;
        }

        /// <summary>
        /// 测试实体Mono添加组件
        /// </summary>
        [UnityTest]
        public IEnumerator TestEntity_Mono_AddGetCSharpComponent()
        {
            GameObject obj = new GameObject();
            EntityMono entityMono = obj.AddComponent<EntityMonoDemo>();

            EntityCSharpDemo entityCSharp = entityMono.AddCharpEntity<EntityCSharpDemo>();
            Assert.IsNotNull(entityCSharp);
            Assert.IsNotNull(entityCSharp.EntityMono);

            entityMono.Initialization();

            ComponentDemo_1 component1 = entityMono.entityCSharp.GetComponent<ComponentDemo_1>();
            ComponentDemo_2 component2 = entityMono.entityCSharp.GetComponent<ComponentDemo_2>();

            Assert.IsNotNull(component1.GetParent<EntityCSharpDemo>().EntityMono);
            Assert.AreEqual(component1, entityMono.entityCSharp.GetComponent<ComponentDemo_1>());
            Assert.AreEqual(component2, entityMono.entityCSharp.GetComponent<ComponentDemo_2>());
            yield return null;
        }
    }
}